import React from 'react'
import { HashRouter as Router, Route, Switch, Redirect } from 'react-router-dom'
import Main from './layout/main/index'
import Login from './layout/login/index'
import { connect } from 'react-redux'
function App(props) {
  return (
    <Router>
      <Switch>
        {/* 先写登录，路由匹配是从上到下 */}
        <Route path = "/login" component = { Login } />
        {/* <Route path = "/" component = { Main } /> */}
        <Route path="/" render = { () => {
          // return localStorage.getItem('isLogin') === 'true' ? <Main /> : <Redirect to="/#/login" />
          return props.isLogin ? <Main /> : <Redirect to="/#/login" />
        }} />
      </Switch>
    </Router>
  )
}

export default connect((state) => {
  return {
    isLogin: state.getIn(['user', 'isLogin'])
  }
})(App)
